﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using LEEAAttendanceControl.Web;
using LEEAAttendanceControl.Web.Services;

using System.ServiceModel.DomainServices.Client;

namespace LEEAAttendanceControl.Views
{
    public partial class CompanyDetails : ChildWindow
    {
        LEEAContext context = new LEEAContext();

        public CompanyDetails()
        {
            InitializeComponent();
        }

        public void LoadData(int id)
        {
            context.Load(context.GetCompanyByIdQuery(id), OnCompanyLoadCompleted, null);
        }

        private void OnCompanyLoadCompleted(LoadOperation operation)
        {
            if (operation.HasError)
            {
                operation.MarkErrorAsHandled();
                MessageDisplay message = new MessageDisplay(ApplicationStrings.GeneralError
                    , ApplicationStrings.GeneralError, "Error");

                message.Show();
            }
            else
            {
                Company company = operation.Entities.FirstOrDefault() as Company;

                if (company != null)
                {
                    DataContext = company;
                }
            }
            
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }
    }
}

